package com.touni.designpattern.flyweightpattern;

import com.touni.designpattern.flyweightpattern.inter.Circle;
import com.touni.designpattern.flyweightpattern.inter.Shape;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @ClassName : ShapeFactory
 * @Description :
 * @Author : lwq
 * @Date: 2020-11-12 14:47
 */
public class ShapeFactory {
    public static Map<String, Circle> colorShapeMap = new ConcurrentHashMap<>();

    public static Circle getShape(String color){
        Circle shape = colorShapeMap.get(color);
        if (shape == null){
            shape = new Circle(color);
            System.out.println("create new color shape color=" + color);
            colorShapeMap.put(color,shape);
        }
        return shape;
    }



}
